package com.jnu.hospitalexamination.mapper;

import com.jnu.hospitalexamination.dto.OrdersUserQueryDTO;
import com.jnu.hospitalexamination.entity.Users;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jnu.hospitalexamination.entity.vo.UserOrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
* @author Nowonder
* @description 针对表【users】的数据库操作Mapper
* @createDate 2024-07-21 23:00:48
* @Entity com.jnu.hospitalexamination.entity.Users
*/
@Mapper
public interface UsersMapper extends BaseMapper<Users> {

    /**
     * 根据用户信息查询用户预约
     * @param phone
     * @param realName
     * @param sex
     * @param smId
     * @param orderDate
     * @param state
     * @return
     */
    @Select("<script>"
            + "SELECT o.orderId, u.phone, u.realName, u.sex, sm.name AS setmealName, "
            + "       hp.name AS hospitalName, o.orderDate, o.state "
            + "FROM orders o "
            + "JOIN users u ON u.userId = o.userId "
            + "JOIN setmeal sm ON sm.smId = o.smId "
            + "JOIN hospital hp ON hp.hpId = o.hpId "
            + "<where>"
            + "  <if test=\"phone != null\">"
            + "    u.phone = #{phone} "
            + "  </if>"
            + "  <if test=\"realName != null\">"
            + "    AND u.realName = #{realName} "
            + "  </if>"
            + "  <if test=\"sex != null\">"
            + "    AND u.sex = #{sex} "
            + "  </if>"
            + "  <if test=\"smId != null\">"
            + "    AND sm.smId = #{smId} "
            + "  </if>"
            + "  <if test=\"orderDate != null\">"
            + "    AND o.orderDate = #{orderDate} "
            + "  </if>"
            + "  <if test=\"state != null\">"
            + "    AND o.state = #{state} "
            + "  </if>"
            + "</where>"
            + "</script>")
    List<UserOrderVO> findOrdersByConditions(
            @Param("phone") String phone,
            @Param("realName") String realName,
            @Param("sex") Integer sex,
            @Param("smId") Integer smId,
            @Param("orderDate") Date orderDate,
            @Param("state") Integer state);
}




